package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.baihang.BaihangAntifraudprdRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百行-反欺诈评分
 *
 * @author guoqiang
 */
public class BaihangAntifraudprdParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 百行-反欺诈评分
     *
     * @param model
     * @throws InterruptedException
     * @throws IOException
     */
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaihangAntifraudprdRecord obj = (BaihangAntifraudprdRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful);
        sb.append(formatValue(obj.getCode())).append(CRT001);
        sb.append(formatValue(obj.getMessage())).append(CRT001);
        sb.append(formatValue(obj.getErrorCode())).append(CRT001);
        sb.append(formatValue(obj.getErrorMessage())).append(CRT001);
        sb.append(formatValue(obj.getBusSerialNo())).append(CRT001);
        sb.append(formatValue(obj.getPersonCreditIndices())).append(CRT001);
        sb.append(formatValue(obj.getPersonCheatIndices())).append(CRT001);
        sb.append(formatValue(obj.getLoanActiveIndices())).append(CRT001);
        sb.append(formatValue(obj.getBreakActiveIndices())).append(CRT001);
        sb.append(formatValue(obj.getGangCreditLabel())).append(CRT001);
        sb.append(formatValue(obj.getGangCheatIndices())).append(CRT001);
        sb.append(formatValue(obj.getGangActiveIndices())).append(CRT001);
        sb.append(formatValue(obj.getGangScaleIndices())).append(CRT001);
        sb.append(formatValue(obj.getCheatNameHit())).append(CRT001);
        sb.append(formatValue(obj.getRiskCode())).append(CRT001);
        sb.append(formatValue(obj.getRiskDegree())).append(CRT001);
        sb.append(formatValue(obj.getRiskScore())).append(CRT001);
        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_baihang_antifraudprd_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIHANG_ANTIFRAUDPRD_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百行-反欺诈评分";
    }
}
